<?php
namespace api\modules\v1\models\circle;

use api\modules\v1\models\friend\Friend;
use api\modules\v1\models\user\User;
use common\models\friend\FriendApply;
use common\models\Functions;
use common\models\Status;
use Yii;
use yii\base\Exception;

class CircleCommentAtRelation extends \common\models\circle\CircleCommentAtRelation
{
    /**
     * 记录@用户
     * @param array $atUserTxCode
     * @param int $commentId
     * @param int $circleId
     * @param array $user
     * @return bool
     * @throws Exception
     */
    public function record($atUserTxCode = [], $commentId = 0, $circleId = 0,$user = []) {

        if (!$atUserTxCode || !$circleId || !$commentId) {
            return true;
        }

        $atUser = User::getByWhere(['tx_code' => $atUserTxCode],['id','tx_code']);
        $insertData = [];
        foreach ($atUser as $key => $value) {
            $insertData[] = [
                'comment_id' => $commentId,
                'circle_id' => $circleId,
                'topic_user_id' => $value['id'],
                'create_time' => date('Y-m-d H:i:s'),
                'tx_code' => $value['tx_code'],
                'is_read' => Status::COMMON_RADIO_NO,
            ];
//            (new FriendApply())->notReadApplyNum($value['id']);
            (new FriendApply())->notReadApplyNum($value['id'],0,'',date('Y-m-d H:i:s'),"{$user['nick_name']}在评论中@了你，前去查看");

        }

        if ($insertData) {
            static::insertManyData($insertData);
        }
        return true;
    }


}
